package com.blt.car.me;

import android.os.Environment;
import android.view.View;

import com.blt.car.R;
import com.blt.car.base.BaseActivity;
import com.blt.car.base.ViewHolder;

import java.io.File;

import blt.app_core.api.base.CoreManager;
import blt.app_core.api.journey.JourneyApi;
import blt.app_core.api.login.LoginApi;
import blt.app_core.api.other.OutApi;
import blt.app_core.log.Logger;
//import in.srain.cube.views.ptr.PtrDefaultHandler;
//import in.srain.cube.views.ptr.PtrFrameLayout;
//import in.srain.cube.views.ptr.PtrHandler;

/**
 * Created by xgp on 2017/6/20.
 */
//该类主要用于接口调试
public class TestApiActivity extends BaseActivity implements View.OnClickListener {

//    PtrFrameLayout ptrFrameLayout;

    @Override
    protected int getLayoutId() {
        return R.layout.activity_test;
    }

    @Override
    protected void initView(ViewHolder holder) {
        holder.get(R.id.logout);
        holder.get(R.id.getCode);
        holder.get(R.id.upload_img);
//        ptrFrameLayout = holder.get(R.id.store_house_ptr_frame);
//        ptrFrameLayout.setPtrHandler(new PtrHandler() {
//            @Override
//            public void onRefreshBegin(PtrFrameLayout frame) {
//                frame.postDelayed(new Runnable() {
//                    @Override
//                    public void run() {
//                        ptrFrameLayout.refreshComplete();
//                    }
//                }, 1800);
//            }
//
//            @Override
//            public boolean checkCanDoRefresh(PtrFrameLayout frame, View content, View header) {
//                return PtrDefaultHandler.checkContentCanBePulledDown(frame, content, header);
//            }
//        });

        holder.setOnClickListener(this, R.id.logout, R.id.getCode, R.id.upload_img);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.logout:
                CoreManager.getCore(LoginApi.class).logout();
                break;
            case R.id.getCode:
//                CoreManager.getCore(LoginApi.class).getVerCode("18071875500");
                CoreManager.getCore(JourneyApi.class).snatchRedpacket(1);
                break;
            case R.id.upload_img:
                String path = Environment.getExternalStorageDirectory() + "/load.png";
                Logger.d(path);
                File file = new File(path);
                if (!file.exists()) {
                    toastShort("文件不存在");
                    return;
                }
//                CoreManager.getCore(LoginApi.class).upload(path);

                CoreManager.getCore(OutApi.class).uploadFile(path);
                break;
        }

    }
}
